
type Method = "GET" | "POST" | "OPTIONS" | "HEAD" | "PUT" | "DELETE" | "TRACE" | "CONNECT" | undefined;

import env from '@/env'
let subDomain = '/api';
const request = (url: string, method: Method, data?: Object) => {
    let _url = env.baseUrl + subDomain + url
    return new Promise((resolve, reject) => {
        uni.showLoading({})
        uni.request({
            url: _url,
            method: method,
            data: data,
            header: {
                'Content-Type': 'application/json',
                "x-requested-with": "XMLHttpRequest",
            },
            success(request) {
                resolve(request.data)
                uni.hideLoading()
            },
            fail(error) {
                reject(error)
                uni.hideLoading()
            },
            complete(aaa) {
                uni.hideLoading()
            }
        })
    })
}

export default request